package com.yzs.controller.front;

import com.yzs.common.bean.R;
import com.yzs.entity.House;
import com.yzs.service.IHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
@CrossOrigin
@RequestMapping("/house")
public class HouseFrontController {
    @Autowired
    IHouseService hs;

    @RequestMapping("getNewHouse")
    public R getNewHouse(@RequestParam Integer i) {
        return hs.getNewHouse(5);
    }

    @RequestMapping("getMyHouse")
    public R getMyHouse(HttpServletRequest req) {
        String token = req.getHeader("token");
        return hs.getMyHouse(token);
    }

    @RequestMapping("createHouseByUser")
    public R createHouseByUser(@RequestBody House house, HttpServletRequest req) {
        String token = req.getHeader("token");
        return hs.createHouse(token, house);
    }

    @RequestMapping("getHouseByPageAsFilter")
    public R getHouseByPageAsFilter(@RequestParam Integer currentPage, @RequestParam Integer pageSize, @RequestParam String zone, @RequestParam String price, @RequestParam String area) {
        return hs.getHouseByPageAsFilter(currentPage, pageSize, zone, price, area);
    }

    @RequestMapping("getVillage")
    public R getVillage() {
        return hs.getVillage();
    }

    @RequestMapping("searchHouseByVillage")
    public R searchHouseByVillage(@RequestParam String village) {
        return hs.searchHouseByVillage(village);
    }

    @RequestMapping("deleteHouse")
    public R deleteHouse(@RequestBody House house){
        return hs.deleteHouse(house);
    }



    @RequestMapping("testUpload")
    public R testUpload(@RequestParam("files") MultipartFile[] files) {
        for (MultipartFile file : files) {
            System.out.println(1);
            System.out.println(file.getSize());
        }
        return null;
    }
}
